﻿@model KRM.Core.tblLoad
@{ViewBag.Title = "ManagerDeliveryFiles";
  Layout = "~/Views/Shared/_popupLayout.cshtml";
}
<script>
    $(document).ready(function () {
        $("#lstDeliveryFile .DeliveryFileItem").click(function () {
            $(this).addClass("selected");
            $("#lstDeliveryFile .DeliveryFileItem").not(this).removeClass('selected');
        });

        $('#frUploadOrderfile').submit(function() {
            var formData = new FormData($("#frUploadOrderfile")[0]);
            $.ajax({
                url: '/orderview/UploadOrderDeliveryFile',
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    if (data != "") {
                        alert(data);
                    } else {
                        ViewOrderDeliveryFolder($('#FolderPath').val(), $('#SelectedOrderRef').val());
                    }
                    App.unblockUI($('#bulkload'), false);
                },
                error: function(error) {
                    $('#FileName').val("");
                    App.unblockUI($('#bulkload'), false);
                }
            });
            return false;
        });
    });
</script>
@if (Model != null)
{
    <div style="padding: 10px">
        <input type="hidden" id="SelectedDeliveryFileName" value=""/>
        <input type="hidden" name ="FolderPath" id="FolderPath" value="@Server.UrlEncode(ViewBag.Folder)"/>
        <form style="display: none" method="POST" action="/Orderview/UploadDeliveryFile" id="frUploadfile" enctype="multipart/form-data">
            <input type="file" name="FileUpload" style="float: right" id="inputUploadfile" onchange="$('#frUploadfile').submit()" />
            <input type="hidden" name="loadcode" value="@Model.LoadCode"/>
            <input type="hidden" name="orderitemId" id="orderitemid" value="@Request["orderItemId"]"/>
        </form>
        <form style="display: none" method="POST" action="/Orderview/UploadOrderDeliveryFile" id="frUploadOrderfile" enctype="multipart/form-data">
            <input type="file" name="FileUpload" style="float: right" id="inputUploadOrderfile" onchange="$('#frUploadOrderfile').submit()" />
            <input type="hidden" name ="OrderRef" id="SelectedOrderRef" value=""/>
            <input type="hidden" name="loadcode" value="@Model.LoadCode"/>
        </form>

        <div class="row-fluid">
            <div class="span4">
                <fieldset>
                    <legend>List Files</legend>
                    <div class="row-fluid">
                        Load Code: @Model.LoadCode
                        <div class="btn-group" style="float: right">
                            <a href="#" data-toggle="dropdown" class="btn dropdown-toggle"><i class="icon-cog"></i><span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="#" onclick="AddToSelectedFolder('@Model.LoadCode')">Add To Selected Order</a>
                                </li>
                                <li>
                                    <a href="#" onclick="DeleteDeliveryFile()">Delete File</a>
                                </li>
                                <li>
                                    <a target="_blank" href="/products/ProductInstructions?path=@ViewBag.Folder&isShortCut=True">Open Folder</a>
                                </li>
                            </ul>
                        </div>
                        <button type="button" class="btn btn-primary" style="float: right" onclick="$('#inputUploadfile').click()"><i class=" icon-plus"></i> Import</button>

                        <div class="row-fluid">
                            <div class="span12" style="border: solid 1px gray; margin-top: 10px; height: 570px;" id="lstDeliveryFile">
                                @foreach (var item in ViewBag.ListFile)
                                {
                                    <div class="DeliveryFileItem" data-path='@Server.UrlEncode(item)' style="float: left; margin: 5px; border: solid 1px gainsboro; padding: 5px" onclick="ViewDeliveryFile('@Request.UserHostAddress','@Server.UrlEncode(item)')">
                                        <div style="text-align: center">
                                            <img src="~/img/Load/delivery_note_icon.png" />
                                        </div>
                                        <div>@Path.GetFileName(item).Replace(".pdf", "")</div>
                                    </div>
                                }
                            </div>
                        </div>
                    </div>
                </fieldset>
            </div>
            <div class="span8">
                <button type="button" class="btn btn-sm" style="position: absolute; right: 20px; margin-top: 18px;" onclick="$('#divViewLoadDetail').show()">
                    <i class="icon-arrow-down"></i>
                </button>
                <div id="divViewLoadDetail">
                    <button type="button" class="btn btn-primary" style="position: absolute;right: 60px;top: 28px;" onclick="$('#inputUploadOrderfile').click()"><i class=" icon-plus"></i> Import</button>
                        <button type="button" class="btn btn-sm" style="position: absolute; right: 20px; margin-top: 18px;" onclick="$('#divViewLoadDetail').hide()">
                        <i class="icon-arrow-up"></i>
                    </button>
                    <div class="row-fluid">
                        <div class="fieldset" style="margin-top: 18px;">
                            <div class="legend"><span>List Order</span></div>
                            <div class="small-scroll" style="height: 200px; padding-top: 20px">
                                <table class="table table-bordered table-fix tbl-selected" data-height="200">
                                    <thead>
                                        <tr>
                                            <th>ItemStatusID
                                            </th>
                                            <th>OrderRef
                                            </th>
                                            <th>Postcode
                                            </th>
                                            <th>OrderItemID
                                            </th>
                                            <th>Qty
                                            </th>
                                            <th>Product
                                            </th>
                                            <th>SpecialInstructions
                                            </th>
                                            <th>WeightKG
                                            </th>
                                            <th>Packages
                                            </th>
                                            <th>Customer
                                            </th>
                                            <th>Address
                                            </th>
                                            <th>Telephone1
                                            </th>
                                            <th>Telephone2
                                            </th>
                                            <th>EmailAddress
                                            </th>
                                            <th>ProductID
                                            </th>
                                            <th>ProductOptionID
                                            </th>
                                            <th>DatePlaced
                                            </th>
                                            <th>WarehouseID
                                            </th>
                                            <th>carrierName
                                            </th>
                                            <th>carrierID
                                            </th>
                                            <th>DropID
                                            </th>
                                            <th>OrderID
                                            </th>
                                            <th>LoadID
                                            </th>
                                            <th>ItemCancelled
                                            </th>
                                            <th>DropNumber
                                            </th>
                                            <th>Mobile
                                            </th>
                                            <th>DeliveryDate
                                            </th>
                                            <th></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach (var item in ViewBag.SelectedLoadItems)
                                        {
                                            <tr onclick="$('#SelectedOrderRef').val('@item.OrderRef');ViewOrderDeliveryFolder('@Server.UrlEncode(ViewBag.Folder)','@item.OrderRef');">
                                                <td>
                                                    @item.ItemStatusID
                                                </td>
                                                <td>
                                                    @item.OrderRef
                                                </td>
                                                <td>
                                                    @item.Postcode
                                                </td>
                                                <td>
                                                    @item.OrderItemID
                                                </td>
                                                <td>
                                                    @item.Qty
                                                </td>
                                                <td>
                                                    @item.Product
                                                </td>
                                                <td>
                                                    @item.SpecialInstructions
                                                </td>
                                                <td>
                                                    @item.WeightKG
                                                </td>
                                                <td>
                                                    @item.Packages
                                                </td>
                                                <td>
                                                    @item.Customer
                                                </td>
                                                <td>
                                                    @item.Address
                                                </td>
                                                <td>
                                                    @item.Telephone1
                                                </td>
                                                <td>
                                                    @item.Telephone2
                                                </td>
                                                <td>
                                                    @item.EmailAddress
                                                </td>
                                                <td>
                                                    @item.ProductID
                                                </td>
                                                <td>
                                                    @item.ProductOptionID
                                                </td>
                                                <td>
                                                    @item.DatePlaced
                                                </td>
                                                <td>
                                                    @item.WarehouseID
                                                </td>
                                                <td>
                                                    @item.carrierName
                                                </td>
                                                <td>
                                                    @item.carrierID
                                                </td>
                                                <td>
                                                    @item.DropID
                                                </td>
                                                <td>
                                                    @item.OrderID
                                                </td>
                                                <td>
                                                    @item.LoadID
                                                </td>
                                                <td>
                                                    @item.ItemCancelled
                                                </td>
                                                <td>
                                                    @item.DropNumber
                                                </td>
                                                <td>
                                                    @item.Mobile
                                                </td>
                                                <td>
                                                    @item.DeliveryDate
                                                </td>
                                            </tr>
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <fieldset>
                            <legend>Delivery Note</legend>
                            <div id="lstOrderDeliveryFile"></div>
                        </fieldset>
                    </div>
                </div>
                <div class="row-fluid">
                    <fieldset>
                        <legend>Preview</legend>
                        <iframe id="ifViewPDF" style="width: 100%; height: 700px; margin-top: 13px; height: 593px;"></iframe>
                    </fieldset>
                </div>
            </div>
        </div>
    </div>
}
else
{
    <h5>This order item not in load</h5>
}
